<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveRecord::Locking::Optimistic::ClassMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveRecord::Locking::Optimistic::ClassMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/activerecord/lib/active_record/locking/optimistic_rb.html">
                vendor/rails/activerecord/lib/active_record/locking/optimistic.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001306">extended</a>&nbsp;&nbsp;
      <a href="#M001309">locking_column</a>&nbsp;&nbsp;
      <a href="#M001307">locking_enabled?</a>&nbsp;&nbsp;
      <a href="#M001310">quoted_locking_column</a>&nbsp;&nbsp;
      <a href="#M001311">reset_locking_column</a>&nbsp;&nbsp;
      <a href="#M001308">set_locking_column</a>&nbsp;&nbsp;
      <a href="#M001312">update_counters_with_lock</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEFAULT_LOCKING_COLUMN</td>
          <td>=</td>
          <td class="context-item-value">'lock_version'</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M001306" class="method-detail">
        <a name="M001306"></a>

        <div class="method-heading">
          <a href="#M001306" class="method-signature">
          <span class="method-name">extended</span><span class="method-args">(base)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001306-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001306-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 105</span>
105:         <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">extended</span>(<span class="ruby-identifier">base</span>)
106:           <span class="ruby-keyword kw">class</span> <span class="ruby-operator">&lt;&lt;</span><span class="ruby-identifier">base</span>
107:             <span class="ruby-identifier">alias_method_chain</span> <span class="ruby-identifier">:update_counters</span>, <span class="ruby-identifier">:lock</span>
108:           <span class="ruby-keyword kw">end</span>
109:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001309" class="method-detail">
        <a name="M001309"></a>

        <div class="method-heading">
          <a href="#M001309" class="method-signature">
          <span class="method-name">locking_column</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The version column used for optimistic locking. Defaults to
<tt>lock_version</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001309-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001309-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 126</span>
126:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">locking_column</span>
127:           <span class="ruby-identifier">reset_locking_column</span>
128:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001307" class="method-detail">
        <a name="M001307"></a>

        <div class="method-heading">
          <a href="#M001307" class="method-signature">
          <span class="method-name">locking_enabled?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Is optimistic locking enabled for this table? Returns true if the
<tt>lock_optimistically</tt> flag is set to true (which it is, by default)
and the table includes the <tt><a
href="ClassMethods.html#M001309">locking_column</a></tt> column (defaults
to <tt>lock_version</tt>).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001307-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001307-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 115</span>
115:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">locking_enabled?</span>
116:           <span class="ruby-identifier">lock_optimistically</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">columns_hash</span>[<span class="ruby-identifier">locking_column</span>]
117:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001310" class="method-detail">
        <a name="M001310"></a>

        <div class="method-heading">
          <a href="#M001310" class="method-signature">
          <span class="method-name">quoted_locking_column</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Quote the column name used for optimistic locking.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001310-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001310-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 131</span>
131:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">quoted_locking_column</span>
132:           <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">quote_column_name</span>(<span class="ruby-identifier">locking_column</span>)
133:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001311" class="method-detail">
        <a name="M001311"></a>

        <div class="method-heading">
          <a href="#M001311" class="method-signature">
          <span class="method-name">reset_locking_column</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Reset the column used for optimistic locking back to the
<tt>lock_version</tt> default.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001311-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001311-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 136</span>
136:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset_locking_column</span>
137:           <span class="ruby-identifier">set_locking_column</span> <span class="ruby-constant">DEFAULT_LOCKING_COLUMN</span>
138:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001308" class="method-detail">
        <a name="M001308"></a>

        <div class="method-heading">
          <a href="#M001308" class="method-signature">
          <span class="method-name">set_locking_column</span><span class="method-args">(value = nil, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Set the column to use for optimistic locking. Defaults to
<tt>lock_version</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001308-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001308-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 120</span>
120:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_locking_column</span>(<span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
121:           <span class="ruby-identifier">define_attr_method</span> <span class="ruby-identifier">:locking_column</span>, <span class="ruby-identifier">value</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
122:           <span class="ruby-identifier">value</span>
123:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001312" class="method-detail">
        <a name="M001312"></a>

        <div class="method-heading">
          <a href="#M001312" class="method-signature">
          <span class="method-name">update_counters_with_lock</span><span class="method-args">(id, counters)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Make sure the lock version column gets updated when counters are updated.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001312-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001312-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 142</span>
142:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_counters_with_lock</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">counters</span>)
143:           <span class="ruby-identifier">counters</span> = <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">locking_column</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">locking_enabled?</span>
144:           <span class="ruby-identifier">update_counters_without_lock</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">counters</span>)
145:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>